<?php

//防止恶意调用
if (!defined('IN_MOD'))
{
    die('Hacking attempt');
}

// 获取城市分类
if(iffun("getcityclass") == 0)
{
	function getcityclass()
	{
		// 城市分类
		$modulewhere=array();
		$modulewhere['classid'] = 101;
		$modulewhere['limit'] = "all";
		$citycateprovince = configcolumn($modulewhere);
		$citycatelist = array();
		foreach($citycateprovince as $key=>$val)
		{
			// 市
			$modulewhere=array();
			$modulewhere['arrayclass'] = $val['id'];
			$modulewhere['limit'] = "all";
			$modulewhere['order'] = "default";
			$citycatecity = configmodule($modulewhere);
			$val["city"] = $citycatecity;// 存入市
			foreach($citycatecity as $key2=>$val2)
			{
				// 县
				$modulewhere=array();
				$modulewhere['arrayclass'] = $val2['id'];
				$modulewhere['bigclassname'] = "attrid";
				$modulewhere['limit'] = "all";
				$modulewhere['order'] = "default";
				$citycatecounty = configmodule($modulewhere);
				$val["city"][$key2]["county"] = $citycatecounty;// 存入县
				foreach($citycatecounty as $key3=>$val3)
				{			
					// 区
					$modulewhere=array();
					$modulewhere['arrayclass'] = $val3['id'];
					$modulewhere['bigclassname'] = "attrid";
					$modulewhere['limit'] = "all";
					$modulewhere['order'] = "default";
					$citycatearea = configmodule($modulewhere);
					$val["city"][$key2]["county"][$key3]["area"] = $citycatearea;
				}
			}
			$citycatelist[$key] = $val;
		}
		
		$citycatedata = array();
		$citycatedata["省份"]["val"]	= "";
		$citycatedata["省份"]["items"]["城市"]["val"]	= "";
		$citycatedata["省份"]["items"]["城市"]["items"]["区县"]["val"]	= "";
		$citycatedata["省份"]["items"]["城市"]["items"]["区县"]["items"]["乡镇"]	= "";
		foreach($citycatelist as $key=>$val)
		{
			$name = $val["name"];
			$citycatedata[$name]["val"]	= $val["id"];
			foreach($val["city"] as $citykey=>$cityval)
			{
				$citytitle = $cityval["post_title"];
				$citycatedata[$name]["items"][$citytitle]["val"]	= $cityval["id"];
				foreach($cityval["county"] as $countykey=>$countyval)
				{
					$countytitle = $countyval["post_title"];
					$citycatedata[$name]["items"][$citytitle]["items"][$countytitle]["val"]	= $countyval["id"];
					foreach($countyval["area"] as $areakey=>$areaval)
					{
						$areatitle = $areaval["post_title"];
						$citycatedata[$name]["items"][$citytitle]["items"][$countytitle]["items"][$areatitle]	= $areaval["id"];
					}
				}
			}
		}	
		
		$citycatedata = json_encode($citycatedata, JSON_UNESCAPED_UNICODE);
		
		return $citycatedata;
	}
}

// 获取区域数据
if(iffun("getareaclass") == 0)
{
	function getareaclass($cityid)
	{		
		// 县
		$modulewhere=array();
		$modulewhere['arrayclass'] = $cityid;
		$modulewhere['bigclassname'] = "attrid";
		$modulewhere['limit'] = "all";
		$modulewhere['order'] = "default";
		$citycatecounty = configmodule($modulewhere);
		$cityarealist = array();
		foreach($citycatecounty as $key=>$val)
		{		
			// 区
			$modulewhere=array();
			$modulewhere['arrayclass'] = $val['id'];
			$modulewhere['bigclassname'] = "attrid";
			$modulewhere['limit'] = "all";
			$modulewhere['order'] = "default";
			$citycatearea = configmodule($modulewhere);
			$val["area"] = $citycatearea;
			$cityarealist[$key] = $val;
		}	
		
		$citycatedata = array();
		$citycatedata["区县"]["val"]	= "";
		$citycatedata["区县"]["items"]["乡镇"]["val"]	= "";
		foreach($cityarealist as $key=>$val)
		{
			$title = $val["post_title"];
			$citycatedata[$title]["val"]	= $val["id"];
			foreach($val["area"] as $areakey=>$areaval)
			{
				$areatitle = $areaval["post_title"];
				$citycatedata[$title]["items"][$areatitle]["val"]	= $areaval["id"];
			}
		}	
		
		$citycatedata = json_encode($citycatedata, JSON_UNESCAPED_UNICODE);
		
		return $citycatedata;
	}
}

if($hookblock == "citylist")
{
	/* 获取城市分类 */
	$provincelist = configcolumn('zcj_newsclasses',6,'classid','acsort asc, acid asc',100);
	$citylist = seocitytablist($provincelist,'zcj_news','acid','pacid',"status=1",'sort desc, aid desc','aid');
	$allbotclass6 = getbottomclass1("zcj_newsclasses",6,"acid","classid",1);
	$hotcity=configmodule("zcj_news",$allbotclass6,0,'pacid',"type=1 and status=1",'sort desc, aid desc');
	$this->assign('cityarr', $citylist['all']);
	$this->assign('hotcity', $hotcity);	
}

if($hookblock == "cityinfo")
{
	// 分站标题SEO
	$citybotclass = getbottomclass("fastxcms_portal_category", 101, 'id', 'parent_id', 1);
	$demailq = "field1";$seotitle = "field2";
	$seoinfoname['titlename'] = 'post_title';
	$seoinfoname['keywordname'] = 'post_keywords';
	$seoinfoname['descriptionname'] = 'post_excerpt';
	$thseoinfo['title'] = $configbase['config']['title'];
	$thseoinfo['keyword'] = $configbase['config']['keyword'];
	$thseoinfo['description'] = $configbase['config']['description'];
	$thseoinfo['homesite'] = '全国';
	$sitearr = seocitytab("fastxcms_portal_post",$citybotclass,'category_id',$demailq,$seotitle,'id',$seoinfoname,$thseoinfo);
	$configbase['cityname'] = $sitearr['cityname'];
	$configbase['cityid'] = $sitearr['cityid'];
	$configbase['siteseo'] = $sitearr['siteseo'];	
}

// 后台城市分类
if($hookblock == "admincityclass")
{
	$citycatedata = getcityclass();
	
	global $parameter_out;
	$parameter_out["cityclass"] = hook_cascade4cate(0,$citycatedata,array("parameter_default[provinceid]","parameter_default[cityid]","parameter_default[countyid]","parameter_default[areaid]"),array(0,0,0,0),"required");
}

// 后台城市搜索分类
if($hookblock == "adminsearchcityclass")
{
	$citycatedata = getcityclass();
		
	global $modulefilter,$getmoduledata;
	$getmoduledata["cityclass"] = hook_cascade4cate(0,$citycatedata,array("parameter_default[provinceid]","parameter_default[cityid]","parameter_default[countyid]","parameter_default[areaid]"),array($modulefilter['parameter_default']["provinceid"],$modulefilter['parameter_default']["cityid"],$modulefilter['parameter_default']["countyid"],$modulefilter['parameter_default']["areaid"]),"required");
}

// 商家城市分类
if($hookblock == "areaclass")
{	
	global $configbase;

	global $parameter_out;
	if($configbase['cityid'])
	{
		$citycatedata = getareaclass($configbase['cityid']);
		
		$parameter_out["cityclass"] = hook_cascade4cate(0,$citycatedata,array("parameter_default[countyid]","parameter_default[areaid]"),array($data["countyid"],$data["areaid"]),"required");
	}else{
		$citycatedata = getcityclass();
		
		$parameter_out["cityclass"] = hook_cascade4cate(0,$citycatedata,array("parameter_default[provinceid]","parameter_default[cityid]","parameter_default[countyid]","parameter_default[areaid]"),array($data["provinceid"],$data["cityid"],$data["countyid"],$data["areaid"]),"required");
	}
}

// 商家城市搜索分类
if($hookblock == "searchareaclass")
{	
	global $configbase;
	
	if($configbase['cityid'])
	{
		$citycatedata = getareaclass($configbase['cityid']);
		
		$cityclass = hook_cascade4cate(0,$citycatedata,array("parameter_default[countyid]","parameter_default[areaid]"),array($_MGPC_REQ["countyid"],$_MGPC_REQ["areaid"]),"required");
		$this->assign('cityclass', $cityclass);	
	}else{
		$citycatedata = getcityclass();
		
		$cityclass = hook_cascade4cate(0,$citycatedata,array("parameter_default[provinceid]","parameter_default[cityid]","parameter_default[countyid]","parameter_default[areaid]"),array($_MGPC_REQ['parameter_default']["provinceid"],$_MGPC_REQ['parameter_default']["cityid"],$_MGPC_REQ['parameter_default']["countyid"],$_MGPC_REQ['parameter_default']["areaid"]),"required");
		$this->assign('cityclass', $cityclass);		
	}
}
?>